﻿using System;
using System.Text;
using System.Web;

namespace Slippor.Douban.Radio.Assist
{
    public interface ISearch
    {
        String Name {get;}

        void Search(String keyword);
    }

    public abstract class BaseSearch : ISearch
    {
        protected String _encoder = "gb2312";
        protected String _searchUrl = String.Empty;
        protected String _name = String.Empty;

        #region ISearch Members

        public void Search(String keyword)
        {
            String word = HttpUtility.UrlEncode(keyword.Trim(), Encoding.GetEncoding(_encoder));
            System.Diagnostics.Process.Start(String.Format(_searchUrl, word));
        }

        public virtual String Name
        {
            get { return _name; }
        }

        #endregion
    }

    public class BaiduSearch : BaseSearch
    {
        public BaiduSearch()
        {
            _searchUrl = "http://mp3.baidu.com/m?tn=baidump3&ct=134217732&lm=-1&word={0}";
            _name = "百度";
        }
    }

    public class DoubanSearch : BaseSearch
    {
        public DoubanSearch()
        {
            _searchUrl = "http://music.douban.com/song_search?q={0}";
            _encoder = "utf-8";
            _name = "豆瓣";
        }
    }
    public class GoogleSearch : BaseSearch
    {
        public GoogleSearch()
        {
            _searchUrl = "http://www.google.cn/music/search?q={0}&aq=t";
            _encoder = "utf-8";
            _name = "谷歌";
        }
    }
    public class SougouSearch : BaseSearch
    {
        public SougouSearch()
        {
            _searchUrl = "http://mp3.sogou.com/music.so?query={0}";
            _name = "搜狗";
        }
    }
    public class KuwoSearch : BaseSearch
    {
        public KuwoSearch()
        {
            _searchUrl = "http://sou.kuwo.cn/ws/Search?pn=1&key={0}&type=yinyue&cat=music";
            _encoder = "utf-8";
            _name = "酷我";
        }
    }
}
